package com.meltingslime.asciifight.common.util;

import java.nio.ByteBuffer;

/**
 * @author Exit93
 * @version 1.0
 */
public class BitConverter {

    /**
     * Converts a byte array to an Integer
     * @param data The array
     * @return Integer value
     */
    public static int toInt(byte[] data){
        ByteBuffer wrapped = ByteBuffer.wrap(data); // big-endian by default
        return wrapped.getInt();
    }

    /**
     * Converts an Integer to a byte array
     * @param num The integer
     * @return Byte Array
     */
    public static byte[] toByteArray(int num){
        ByteBuffer dbuf = ByteBuffer.allocate(4);
        dbuf.putInt(num);
        return dbuf.array();
    }
}
